package com.tangsm.api.demo.mapper;

import com.tangsm.api.demo.domain.Student;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.Date;

@Mapper
@Component
public interface StudentMapper {
    /**
     * 新增
     * @param student
     * @return
     */
    @Insert("insert into student(sno,sname,ssex) values(#{sno},#{name},#{sex})")
    int add(Student student);

    /**
     * 按学号修改
     * @param student
     * @return
     */
    @Update("update student set sname=#{name},ssex=#{sex} where sno=#{sno}")
    int update(Student student);

    /**
     * 按学号删除
     * @param sno
     * @return
     */
    @Delete("delete from student where sno=#{sno}")
    int deleteBysno(String sno);

    /**
     * 按学号查询
     * @param sno
     * @return
     */
    @Select("select * from student where sno=#{sno}")
    @Results(id = "student", value = {
            @Result(property = "id", column = "id", javaType = Long.class),
            @Result(property = "sno", column = "sno", javaType = String.class),
            @Result(property = "name", column = "sname", javaType = String.class),
            @Result(property = "sex", column = "ssex", javaType = String.class),
            @Result(property = "createBy", column = "create_by", javaType = String.class),
            @Result(property = "createTime", column = "create_time", javaType = Date.class),
            @Result(property = "updateBy", column = "update_by", javaType = String.class),
            @Result(property = "updateTime", column = "update_time", javaType = Date.class)
    })
    Student queryStudentBySno(String sno);
}